#include "main/utils.h"
using namespace std;

class Solution {
  public:
    int longestConsecutive(vector<int>& nums) {
      unordered_set<int> num_set;
      for (const int& n : nums) {
        num_set.insert(n);
      }

      int max_len = 0;
      for (const int& n : num_set) {
        if (!num_set.count(n - 1)) {
          int cur_len = 1;
          int cur_num = n;
          while (num_set.count(cur_num + 1)) {
            cur_num++;
            cur_len++;
          }
          if (cur_len > max_len) {
            max_len = cur_len;
          }
        }
      }
      return max_len;
    }
};

int main() {
  vector<int> input = {100, 4, 200, 1, 3, 2};
  Solution su;
  cout << su.longestConsecutive(input) << endl;
}
